<?php
namespace app\admins\controller;
use think\Controller;
use Util\data\Sysdb;



class labels extends BaseAdmin
{
	public function channel(){
		$channel['lists']=$this->db->table('admin_labels')->where(array('flag'=>'channel'))->lists();
		$this->assign('data',$channel);

		return $this->fetch();
	}

	public function area(){
		$channel['lists']=$this->db->table('admin_labels')->where(array('flag'=>'area'))->lists();
		$this->assign('data',$channel);

		return $this->fetch();
	}

	public function charge(){
		$channel['lists']=$this->db->table('admin_labels')->where(array('flag'=>'charge'))->lists();
		$this->assign('data',$channel);

		return $this->fetch();

	}

	public function save(){

		$flag=trim(input('post.flag'));
		$ord=input('post.ord/a');
		$title=input('post.title/a');
		$status=input('post.status/a');//tp传数组方式

		foreach ($ord as $key => $value) {
			//新增
			
			$data['ord']=$value;
			$data['title']=$title[$key];
			$data['status']=isset($status[$key])? 1: 0;
			$data['flag']=$flag;  


			if($key==0&& $data['title']){
				$this->db->table('admin_labels')->insert($data);
			}
			if($key>0){
				if($data['title']==''){
					//删除
					$this->db->table('admin_labels')->where(array('id'=>$key))->delete();
				}else{
					//修改
					$this->db->table('admin_labels')->where(array('id'=>$key))->update($data);
				}
			}

		}
		exit(json_encode(array('code'=>0,'msg'=>'保存成功')));


	}


}